/* 
 * File:   MPIMaster.h
 * Author: mpienv
 *
 * Created on July 27, 2011, 4:55 PM
 */

#ifndef MPIMASTER_H
#define	MPIMASTER_H

#include <mpi.h>
#include "../libGRASP/MGrasp.h"
#include "../libParallel/MPIBasics.h"
#include "Util.h"



/**
 * Qual o signifcado de maxEvals (tem sentido de usa-lo no MPIMaster ?)
 * @param mgrasp
 * @param iter
 */
class MPIMaster {
public:
    MPIMaster(int size, MGrasp *mgrasp, int iter, int maxEvals);
    MPIMaster(const MPIMaster& orig);
    virtual ~MPIMaster();
    Funcao* startDaemon();
    bool verifyGap(double fX, double *tempX, int totalEvals);
    void updateIfBest(double fTempX, double *tempX, double h, bool onlyGlobal); 
    int totalSlavesEvals();
    int getResultTotalEvals();
    double getResultGAP();
    bool mustFinish(double fX, double *tempX, int totalEvals, double fBest);
private:
    int size;
    void initEnv();
    int indexGap;
    MGrasp *mgrasp;
    Funcao *func;
    int maxIter, currentIter;
    double he;
    int n;
    int *slaves_iters, *evals, *slaves_fn_evals, *slave_current_round;
    double *best, *gaps, *bestIter;
    double fBest, hBest, fBestIter, hBestIter;
    int maxEvals, result_total_evals;
    double result_gap;
    

};

#endif	/* MPIMASTER_H */

